package com.finchina.myview.shader;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

/**
 * 作者：黄赛赛 on 2015/9/21 09:52
 *
 * @version V1.0
 * @Description: ${todo}()
 */
public class RadialGradientShaderView extends View {
    Paint paint;
    int screenX, screenY;
    public RadialGradientShaderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        screenX = getMeasuredWidth();
        screenY = getMeasuredHeight();
    }

    @Override
    protected void onDraw(Canvas canvas) {
//        super.onDraw(canvas);
        paint.setShader(new RadialGradient(screenX / 2, screenY / 2, screenX / 2, Color.RED, Color.YELLOW, Shader.TileMode.CLAMP));
//        canvas.drawRect(0,0,screenX,screenY, paint);
        canvas.drawCircle(screenX / 2, screenY / 2, screenX / 2,  paint);
    }
}
